package com.dzl.partition.service.impl;

import com.dzl.base.service.BaseServiceImpl;
import com.dzl.partition.dao.WelfarePartitionMapper;
import com.dzl.partition.pojo.WelfarePartition;
import com.dzl.partition.pojo.query.WelfarePartitionQuery;
import com.dzl.partition.pojo.vo.WelfarePartitionVo;
import com.dzl.partition.service.WelfarePartitionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 分区表(WelfarePartition)表服务实现类
 * @author caobucao
 * @date 2021-05-21 17:34:43
 */
@Service
public class WelfarePartitionServiceImpl extends BaseServiceImpl<WelfarePartition> implements WelfarePartitionService {

    @Autowired
    private WelfarePartitionMapper mapper;

    @Override
    public PageInfo<WelfarePartitionVo> selectPartitionListPage(WelfarePartitionQuery query) {
        PageHelper.startPage(query);
        List<WelfarePartitionVo> list = mapper.selectPartitionVoList(query);
        PageInfo<WelfarePartitionVo> page = new PageInfo<WelfarePartitionVo>(list);
        return page;
    }

    @Override
    public List<WelfarePartitionVo> selectPartitionListData(WelfarePartitionQuery query) {
        List<WelfarePartitionVo> list = mapper.selectPartitionVoList(query);
        return list.stream().filter(x -> x.getId() != 0).collect(Collectors.toList());
    }

    @Override
    public List<WelfarePartitionVo> selectPartitionList(Integer enterpriseId) {
        try {
            List<WelfarePartitionVo> list = mapper.selectPartitionList(enterpriseId);
            //由于全部分区没有商品，需在此骗自己
            WelfarePartitionVo welfarePartitionVo = new WelfarePartitionVo();
            welfarePartitionVo.setId(0);
            welfarePartitionVo.setPartitionName("全部分区");
            list.add(0,welfarePartitionVo);
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("列表加载失败！");
        }
    }

    @Override
    public Integer selectCountGoodsById(Integer id) {
        return mapper.selectCountGoodsById(id);
    }

    @Override
    public Integer selectCountCardTypeByPartitionId(Integer id) {
        return mapper.selectCountCardTypeByPartitionId(id);
    }

    @Override
    public List<WelfarePartition> selectByIds(List<Integer> partitionIdList) {
        return mapper.selectByIds(partitionIdList);
    }
}
